<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>exif-js</title>
    <script src="./exif.js"></script>
    <script src="./binaryajax.js"></script>
    <script src="./rotate.js"></script>

    <!-- exif文档地址: http://code.ciaoca.com/javascript/exif-js/ -->
    <!-- exif维基百科: https://zh.wikipedia.org/zh-cn/Exif -->
</head>

<body>
    <input id="put" type="file" />
    <script>
        // BinaryAjax('1.webp', function (o) {
        //     console.log(o)
        //     console.log(o.binaryResponse)
        //     var oExif = EXIF.getData(o.binaryResponse, (orientation) => {
        //         console.log({ orientation })
        //     })
        //     var orientation = oExif.Orientation
        //     console.log(orientation)
        //     return
        //     var html = [];
        //     html.push('<ol>');
        //     for (var key in oExif) {
        //         var val = oExif[key];
        //         html.push('<li>', key, '&nbsp;&nbsp;:&nbsp;&nbsp;<em>');
        //         html.push(val, '</em></li>');
        //     }
        //     html.push('</ol>');
        //     document.getElementById('console').innerHTML = html.join('');

        //     var img = document.getElementById('img');
        //     switch (orientation) {
        //         case 6:
        //             Rotate(img, '90deg');
        //             break;
        //         case 3:
        //             Rotate(img, '180deg');
        //             break;
        //         case 8:
        //             Rotate(img, '270deg');
        //             break;
        //     }
        // });
        put.addEventListener('change', (e) => {
            const file = put.files[0];

            // EXIF.getData(file, function (result) {
            //     console.log(result);
            // });

            try {
                // console.log(EXIF.readFromBinaryFile(file))
                // if (!/\/(?:jpeg|png|gif)/i.test(file.type)) return;
                const rd = new FileReader();
                rd.onload = (evt) => {
                    let url = evt.target.result;
                    // 不能使用页面中的img,页面中的img会压缩图片!
                    const img = new Image();
                    img.src = url;
                    img.onload = () => {
                        EXIF.getData(img, function (result) {
                            console.log(result);
                        });
                    };
                };
                // 将文件转换为 base64 的 url
                rd.readAsDataURL(file);
            } catch (e) {
                console.error(`file exp:${e.message}`);
            }
        })
    </script>
</body>

</html>